import { View, Text } from '@tarojs/components'
import { useLoad } from '@tarojs/taro'
import './index.scss'
import Taro from '@tarojs/taro'

export default function BuyMedicine () {
  useLoad(() => {
    console.log('Page loaded.')
  })
  function jumpToWhMiniProgram(){
    let token = Taro.getStorageSync('token')
    let whToken = Taro.getStorageSync('whToken')
    let patientId = Taro.getStorageSync('patientId')
    if(token){
      Taro.navigateToMiniProgram({
        appId: 'wx2db0b20b87789f11',
        extraData: {
          token,
          whToken,
          patientId
        },
        envVersion: 'trial',
        success(res) {
          // 打开成功
          console.log(res)
        }
      })
    }else {
      Taro.showToast({
        title: '请先登录',
        icon: 'none',
        duration: 2000
      })
    }
  }
  return (
    <View className='buyMedicine'>
      <Text>Hello world!</Text>
      <View className='fuli-buy-btn' onClick={jumpToWhMiniProgram}>福利购药</View>
    </View>
  )
}
